using Microsoft.Xna.Framework;
using System;

namespace Xfinity.Entities.Managers
{
    /// <summary>
    /// An entity that's also a service.
    /// </summary>
    public class GlobalManager : LogicalEntity
    {
        private bool updates;
        /// <summary>
        /// Constructs a new global manager, and adds it to Game.Components and Game.Services.
        /// </summary>
        /// <param name="managerName">The name of the manager.</param>
        /// <param name="updates">Wether or not the manager updates every frame.</param>
        /// <param name="game">The Game.</param>
        public GlobalManager(string managerName, bool updates, Game game)
            : base(managerName, game)
        {
            this.updates = updates;
            RegisterManager();
        }
        /// <summary>
        /// Initialises the global manager.
        /// </summary>
        public override void Initialize()
        {
            Enabled = updates;

            base.Initialize();
            GC.Collect();
            //Game.Components.Remove(this);
        }
        /// <summary>
        /// Registers the manager to Game.Components and Game.Services.
        /// </summary>
        protected virtual void RegisterManager()
        {
            if (Game != null)
            {

                if ((Game.Services.GetService(GetType())) == null)
                {
                    Game.Services.AddService(this.GetType(), this);
                    Game.Components.Add(this);
                }

                
            }
        }
    }
}
